<template>
  <div>
    <el-header class="header">
      <div>工具管理系统</div>
      <div id="logout">
        <el-button type="primary" @click="logout">退出登录</el-button>
      </div>
    </el-header>
    <el-container class="container">
      <el-aside class="aside" style="background-color: #34495e;">
        <el-menu class="el-menu-vertical-demo" background-color="#34495e" text-color="#ecf0f1"
                 active-text-color="#e67e22" router :default-active="menuActive">
          <el-submenu :index="item.id" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i class="el-icon-folder" style="color: #e67e22;"></i> {{ item.name }}
            </template>
            <el-menu-item :index="subItem.url" v-for="subItem in item.children" :key="subItem.id"
                          @click="menuActive=subItem.url"
                          :style="{ transition: 'background-color 0.3s' }">
              <i class="el-icon-document" style="color: #bdc3c7;"></i>
              <template slot="title">{{ subItem.name }}</template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main class="main">
        <router-view></router-view>
      </el-main>
    </el-container>

  </div>
</template>

<script>
export default {
  name: 'home',
  data() {
    return {
      menuList: [],
      menuActive: ''
    }
  },
  created() {
    this.queryMenuList()
  },
  methods: {
    logout() {
      window.sessionStorage.removeItem('token')
      this.$router.push('/login')
    },
    queryMenuList() {
      this.$http.post('menu/tree').then(res => {
        this.menuList = res.data
      }).catch(err => {
         console.log(err)
      })
    }
  }
}
</script>

<style lang="less" scoped>
.header {
  background-color: #333;
  color: #fff;
  height: 20vh;
  line-height: 60px;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
}

.aside {
  background-color: #545c64;
  height: 100%;
}

.main {
  background-color: #fff;
  height: 100%;
  padding: 20px;
}

.container {
  display: flex;
  height: 93vh; /* 更改为视口高度 */
}

.el-menu-item:hover {
  background-color: rgba(231, 126, 34, 0.1);
}

.el-submenu:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

</style>
